<?php
namespace app\frontend\forms;

use app\models\User;
use Phalcon\Forms\Element\Text;
use Phalcon\Forms\Element\Password;
use Phalcon\Forms\Element\Radio;
use Phalcon\Validation\Validator\PresenceOf;
use Phalcon\Validation\Validator\Confirmation;

class ChangePasswordForm extends FormBase
{
    public function initialize(User $user)
    {
        $oldpassword = new Password("oldpassword");
        $oldpassword->addValidators([
            new PresenceOf(['message'=>'原密码不能为空','cancelOnFail'=>true]),
            new Confirmation([
                'with'=>[
                    'oldpassword'=>'userpassword',
                ],
                'message'=>'原密码错误',
            ])
        ]);
        $this->setElement($oldpassword,'原密码',['class'=>'form-control']);

        $this->setElement(new Password("password"),$user->getNote('password'),['class'=>'form-control']);

        $this->setElement(new Text("name"),$user->getNote('name'),['class'=>'form-control']);

        $this->setElement(new Text("mobile"),$user->getNote('mobile'),['class'=>'form-control']);

        $this->setElement(new Text("phone"),$user->getNote('phone'),['class'=>'form-control']);

        $this->setElement(new Text("email"),$user->getNote('user'),['class'=>'form-control']);

        $sex = new Radio('sex');

        $this->setElement($sex,$user->getNote('sex'),['class'=>'form-control','value'=>'1']);

        $sex = new Radio('sex');

        $this->setElement($sex,$user->getNote('sex'),['class'=>'form-control','value'=>'2']);

        $sex = new Radio('sex');

        $this->setElement($sex,$user->getNote('sex'),['class'=>'form-control','value'=>'3']);

        $this->setElement(new Text("duty"),$user->getNote('duty'),['class'=>'form-control']);
    }

}
